<template>
  <a-modal v-model:visible="visible" :footer="true" @cancel="close" :on-before-ok="handleOk" draggable unmountOnClose width="70%">
    <template #title>批量换码</template>
    <div class="mb-5">
      <a-select v-model="actId" :options="actList" :field-names="{ value: 'id', label: 'name' }" placeholder="请选择活动"/>
    </div>
    <ma-upload v-model="fileList" :showList="true" type="image" :multiple="true"/>

  </a-modal>
</template>

<script setup>
import { ref, inject } from 'vue'
import { Message } from '@arco-design/web-vue'
import apiActivity from "@/api/prm/activity.js";
import api from "@/api/prm/activity_qrcode.js";

const emit = defineEmits(['success'])

const visible = ref(false)

const actList = ref([])
const actId = ref('')
const fileList = ref([])

const open = async () => {
  fileList.value = [];
  //获取所有的活动
  const res = await apiActivity.allList({act_type:1})
  if (res.code === 200) {
    actList.value = res.data
  } else {
    Message.error('活动加载失败')
  }
  visible.value = true
}
const close = () => visible.value = false

const handleOk = async () => {
  console.log('aa');
  console.log(fileList.value);
  const res = await api.batchAdd({activity_id:actId.value, files:fileList.value});
  if (res.code === 200) {
    Message.success('成功')
    emit('success')
    close()
  }
}

defineExpose({ open, close })
</script>
